package com.example.leave.component.valid.impl;

import com.example.leave.component.valid.NotBefore;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.sql.Date;
import java.text.SimpleDateFormat;

public class NotBeforeImpl implements ConstraintValidator<NotBefore, Date> {

    @Override
    public void initialize(NotBefore constraintAnnotation) {

    }

    @Override
    public boolean isValid(Date date, ConstraintValidatorContext context) {
        if (null != date) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String currentDate = sdf.format(new java.util.Date());
            String dateParameter = sdf.format(date);
            return currentDate.compareTo(dateParameter) <= 0;
        }
        return true;

    }
}
